{include file="common/head"/}
<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>订单{:lang('list')}</legend>
    </fieldset>
    <div class="demoTable layui-row">
        <div class="layui-form layui-form-pane" style="float:left;">
			<div class="layui-form-item">
				<label class="layui-form-label">快捷查询</label>
				<div class="layui-input-inline layui-form">
					<input class="layui-input" name="key" id="key" placeholder="请输入微信昵称/订单号">
				</div>
			</div>
        </div>
		<div class="layui-form layui-form-pane" style="float:left;width:460px">
			<div class="layui-form-item">
				<label class="layui-form-label">下单时间</label>
				<div style="width:72%" class="layui-input-inline layui-form">
					<input style="width:100%" type="text" class="layui-input" id="test10" placeholder="请选择时间">
				</div>
			</div>	
		</div>
		<div class="layui-form layui-form-pane" style="float:left">
			<div class="layui-form-item">
				<label class="layui-form-label">订单状态</label>
				<div class="layui-input-inline layui-form">
					<select id="statuslist">
						<option value=""></option>
						{volist name="statuslist" id="statuslist"}
						<option value="{$key}">{$statuslist}</option>
						{/volist}
					</select>
				</div>
			</div>		
		</div>
    </div>
	<div class="demoTable layui-row">
		<button class="layui-btn" style="margin-left:30px;margin-top:15px;" id="search" data-type="reload">{:lang('search')}</button>
		<a href="{:url('index')}" style="margin-top:15px;" class="layui-btn">{:lang('reset')}</a>
		<button style="margin-top:15px;" id="dataAll" class="layui-btn">导出数据</button>
	</div>
    <table class="layui-table" id="list" lay-filter="list"></table>
</div>
{include file="common/foot"/}
<script src="__STATIC__/common/js/jquery.2.1.1.min.js"></script>
<script type="text/html" id="status">
	{{# if(d.status==1){ }}
        <div>待付款</div> 
    {{# } }}
	{{# if(d.status==2){ }}
        <div class="layui-btn layui-btn-danger layui-btn-xs" onclick="orderStatus($(this),{{ d.id }})">待发货</div>
    {{# } }}
	{{# if(d.status==3){ }}
        <div>待收货</div> 
    {{# } }}
	{{# if(d.status==4){ }}
        <div>待评价</div> 
    {{# } }}
</script>
<script>

	layui.use('laydate', function(){
		var laydate = layui.laydate;
						
		//日期时间范围
		laydate.render({
			elem: '#test10'
			,type: 'datetime'
			,range: true
		});
	})
     layui.use(['table','form'], function() {
        var table = layui.table,form = layui.form,$ = layui.jquery;
        var tableIn = table.render({
            id: 'ad',
            elem: '#list',
            url: '{:url("index")}',
            method: 'post',
            page:true,
            cols: [[
                {field: 'id',align: 'center', title: '{:lang("id")}', width: 80, fixed: true, sort: true},
                {field: 'nickName', align: 'center',title: '微信昵称', width: 150},
				{field: 'goodsRes', align: 'center',title: '订单详情', width: 300},
                {field: 'order_number', align: 'center',title: '订单号', width: 200},
                {field: 'money', align: 'center',title: '付款金额', width: 150},
                {field: 'status', align: 'center',title: '订单状态', width: 150,toolbar:'#status'},
                {field: 'userName', align: 'center',title: '收货人姓名', width: 150},
				{field: 'detailInfo', align: 'center',title: '收货地址', width: 150},
				{field: 'telNumber', align: 'center',title: '收货人手机号码', width: 150},
                {field: 'add_time',align: 'center', title: '下单时间',width: 200, sort: true}
            ]],
            limit:''
        });
        //搜索
        $('#search').on('click', function () {
			var add_time 	= $('#test10').val();
			var status  = $('#statuslist').val();
			var key  = $('#key').val();
			//alert(addtime);
            if ($.trim(add_time) === '' && $.trim(status) === '' && $.trim(key) === ''){
                layer.msg('{:lang("query_condition")}', {icon: 0});
                return;
            }
				tableIn.reload({
					where: {add_time:add_time,status:status,key:key}
				});
        });
		
    })
	function orderStatus(obj,id){
		layer.confirm('确定要发货吗？', function(index){
			var loading = layer.load(1, {shade: [0.1, '#fff']});
			$.post("{:url('orderStatus')}",{id:id},function(res){
				layer.close(loading);
				if(res.errorCode == 8888){
					layer.msg(res.msg,{time:1000,icon:1},function(){
						obj.attr('onclick','');
						obj.attr('class','');
						obj.text('待收货');
					});
				}else{
					layer.msg(res.msg,{time:1000,icon:2});
				}
			});
			layer.close(index);
        });
    }
	$('#dataAll').click(function(){
		var add_time 	= $('#test10').val();
		var status  = $('#statuslist').val();
		var key  = $('#key').val();
        if ($.trim(add_time) === ''){
			add_time = 0;
		} 
		if ($.trim(status) === ''){
			status = 0;
		} 
		if ($.trim(key) === ''){
			key = 0;
		}
		location.href = '/admin/order/dataall/key/'+key+'/status/'+status+'/add_time/'+add_time+'.html';
	})
	
	
</script>